using Microsoft.EntityFrameworkCore;
using OrchardCore.Data;

namespace OrchardCore.Data.EFCore;

/// <summary>
/// EF Core数据迁移管理器接口
/// 负责管理EF Core数据库迁移的创建、应用和回滚操作
/// </summary>
/// <remarks>
/// 主要功能：
/// - 创建EF Core迁移文件
/// - 应用数据库迁移
/// - 回滚数据库迁移
/// - 检查迁移状态
/// - 生成迁移脚本
/// - 管理迁移历史记录
/// </remarks>
public interface IEFCoreDataMigrationManager
{
    /// <summary>
    /// 获取所有待应用的迁移
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <returns>待应用的迁移列表</returns>
    Task<IEnumerable<string>> GetPendingMigrationsAsync(Type contextType);

    /// <summary>
    /// 获取所有已应用的迁移
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <returns>已应用的迁移列表</returns>
    Task<IEnumerable<string>> GetAppliedMigrationsAsync(Type contextType);

    /// <summary>
    /// 应用所有待应用的迁移
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <returns>应用的迁移数量</returns>
    Task<int> ApplyMigrationsAsync(Type contextType);

    /// <summary>
    /// 创建新的迁移
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <param name="migrationName">迁移名称</param>
    /// <returns>创建的迁移文件路径</returns>
    Task<string> CreateMigrationAsync(Type contextType, string migrationName);

    /// <summary>
    /// 回滚到指定的迁移
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <param name="targetMigration">目标迁移名称</param>
    /// <returns>回滚的迁移数量</returns>
    Task<int> RollbackToMigrationAsync(Type contextType, string targetMigration);

    /// <summary>
    /// 生成迁移脚本
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <param name="fromMigration">起始迁移</param>
    /// <param name="toMigration">目标迁移</param>
    /// <returns>迁移脚本内容</returns>
    Task<string> GenerateMigrationScriptAsync(Type contextType, string fromMigration, string toMigration);

    /// <summary>
    /// 检查数据库是否存在
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <returns>数据库是否存在</returns>
    Task<bool> DatabaseExistsAsync(Type contextType);

    /// <summary>
    /// 确保数据库已创建
    /// </summary>
    /// <param name="contextType">DbContext类型</param>
    /// <returns>是否成功创建数据库</returns>
    Task<bool> EnsureDatabaseCreatedAsync(Type contextType);
} 